package com.yuanfengerp.UserManage.controller;

import com.alibaba.fastjson.JSON;
import com.yuanfengerp.UserManage.model.UserManage;
import com.yuanfengerp.UserManage.service.IUserManageService;
import com.yuanfengerp.publicUtil.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

@RestController
@CrossOrigin
public class UserManageController {
    @Autowired
    private IUserManageService userManageService;

    /**
     *  获取用户列表
     * @param pageSize
     * @param offset
     * @return
     */
    @PostMapping("/getUserManage")
    public ArrayList<UserManage> getUserManage(int pageSize, int offset){
        return userManageService.getUserManage(pageSize,offset);
    }

    /**
     *  获取用户信息
     * @param user_ID
     * @return
     */
    @PostMapping("/getUser")
    public String getUser(int user_ID){
        return JSON.toJSONString(userManageService.getUser(user_ID));
    }
    @PostMapping("/addUser")
    public Result<UserManage> addUser(@RequestBody UserManage user){
        return userManageService.addUser(user);
    }

    /**
     *  更新用户信息
     * @param user
     * @return
     */
    @PostMapping("/updateUser")
    public Result<UserManage> updateUser(@RequestBody UserManage user){
        return userManageService.updateUser(user);
    }

}
